using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PropsPanel : BasePanel, IInitializable
{

    public Sprite[] propsSprite;
    private int propsIndex;
    public Image propsImage;
    public Text propsDesc;
    private List<string> propsDescList = new List<string> { "Add extra 30s", "Refresh all goods", "Change 9 goods the same", "A random container style" };
    private int price = 100;
    public void Initialize(object data)
    {
        Debug.Log("PropsPanel initialized" + data);
        propsIndex = (int)data;
    }
    public void OnCloseClick()
    {
        // 关闭面板
        PanelManager.Instance.ClosePanel<PropsPanel>();
    }

    public override void OnOpen()
    {
        base.OnOpen(); // 调用基类的 OnOpen 方法

        // 在面板打开时执行的逻辑
        Debug.Log("PropsPanel opened");
        propsImage.sprite = propsSprite[propsIndex];
        propsDesc.text = propsDescList[propsIndex];
    }

    public override void OnClose()
    {
        base.OnClose(); // 调用基类的 OnClose 方法

        // 在面板关闭时执行的逻辑
        Debug.Log("PropsPanel closed");
    }

    public void OnBuyClick()
    {
        // 购买道具
        Debug.Log("Buy props" + propsIndex);
        float coins = (float)UserManager.Instance.GetUserInfo()["Coins"];
        if (coins < price)
        {
            Tools.ShowTipToast("Insufficient coins");
            return;
        }
        UserManager.Instance.SubtractCoins(price);
        switch (propsIndex)
        {
            case 0:
                // 增加时间
                // CountdownManager.Instance.AddTime(30);
                PropsManager.Instance.AddProp(PropsManager.PropType.Prop1, 1);
                break;
            case 1:
                // 刷新所有商品
                // SkillManager.Instance.OnRefreshSkills();
                PropsManager.Instance.AddProp(PropsManager.PropType.Prop2, 1);
                break;
            case 2:
                //将9个商品都变成一个样式；（样式随机）
                // SkillManager.Instance.OnChangeSkills();
                PropsManager.Instance.AddProp(PropsManager.PropType.Prop3, 1);
                break;
            case 3:
                PropsManager.Instance.AddProp(PropsManager.PropType.Prop4, 1);
                break;
        }
        OnCloseClick();
    }
}
